package com.ecarx.camera.utils;

import android.os.Environment;
import android.os.StatFs;

import androidx.annotation.NonNull;
import androidx.fragment.app.FragmentManager;

public final class StorageUtils {

    private static final String TAG = StorageUtils.class.getSimpleName();

    private StorageUtils() {
        throw new UnsupportedOperationException("u can't instantiate me...");
    }

    /**
     * 检测磁盘是否占满
     * @param fragmentManager
     * @return almostFull时返回true
     */
    public static boolean checkStorage(@NonNull FragmentManager fragmentManager) {
        // fixme 目前不需要检测磁盘状态
        return false;
    }

    public static String getOutputDirPath() {
        return Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).getAbsolutePath();
    }

    public static boolean isAlmostFull() {
        StatFs fs = new StatFs(getOutputDirPath());
        return (double) fs.getAvailableBytes() / (double) fs.getTotalBytes() <= .1f;
    }

    public static boolean isFull() {
        StatFs fs = new StatFs(getOutputDirPath());
        return fs.getAvailableBytes() <= 400 * 1024 * 1024L;
    }
}
